//
//  HLHomepageHeader.m
//  zhuanxian
//
//  Created by zhaoliang chen on 2017/11/17.
//  Copyright © 2017年 huiling. All rights reserved.
//

#import "HLHomepageHeader.h"
#import "HLAdvertiseObject.h"

@interface HLHomepageHeader()
<SDCycleScrollViewDelegate>

@property(nonatomic,strong)NSMutableArray* arrayUrls;

@end

@implementation HLHomepageHeader

+ (NSString *)headerViewIdentifier {
    return @"HLHomepageHeader";
}

+ (instancetype)headerViewWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
    HLHomepageHeader *headerView = (HLHomepageHeader*)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:[HLHomepageHeader headerViewIdentifier] forIndexPath:indexPath];
    return headerView;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = BackColor;
        self.arrayUrls = [NSMutableArray new];
        
        [self addSubview:self.bannerView];
        [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.mas_equalTo(self);
            make.height.mas_equalTo(220);
        }];
        
        [self addSubview:self.labelHeader];
        [self.labelHeader mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.bannerView.mas_bottom);
            make.left.mas_equalTo(10);
            make.bottom.mas_equalTo(self);
        }];
    }
    return self;
}

- (void)reloadAdvertise:(NSArray*)array {
    [self.arrayUrls removeAllObjects];
    for (int i=0; i<array.count; i++) {
        HLAdvertiseObject* model = array[i];
        [self.arrayUrls addObject:model.imgUrl];
    }
    self.bannerView.imageURLStringsGroup = self.arrayUrls;
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    
}

- (UILabel*)labelHeader {
    if (!_labelHeader) {
        _labelHeader = [[UILabel alloc]init];
        _labelHeader.font = [UIFont systemFontOfSize:10];
    }
    return _labelHeader;
}

- (SDCycleScrollView*)bannerView {
    if (!_bannerView) {
        _bannerView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_MAX_WIDTH, 180) imageURLStringsGroup:@[]];
        _bannerView.delegate = self;
    }
    return _bannerView;
}

@end
